package com.sgb.kjwl.viewmodel.manage;

import android.content.Context;

import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.api.APIManager;
import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.model.entity.manage.CompanyAndDeptEntity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;

import java.util.List;

public class AgentStaffCheckDepartmentModel extends BaseViewModel {

    public MutableLiveData<List<CompanyAndDeptEntity>> departList = new MutableLiveData();

    public MutableLiveData<List<CompanyAndDeptEntity>> companyList = new MutableLiveData();

    //获取公司列表
    public void getCompanyList(Context context) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null)
                .setCanceledOnTouchOutside(false);
        APIManager.getInstance().getUserAPI().getMyCompanyList().enqueue(new ICallBack<BaseEntity<List<CompanyAndDeptEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CompanyAndDeptEntity>> data) {
                DialogHelper.dismissProgressDialog();
                if (data != null && data.getData() != null){
                    companyList.postValue(data.getData());
                }
            }
        });
    }

    //获取公司列表
    public void getDepartmentList(Context context, String companyNo) {
        DialogHelper.showProgressDialog(context, null, "数据加载中...", 0, false, null)
                .setCanceledOnTouchOutside(false);
        APIManager.getInstance().getUserAPI().getDeptList(companyNo).enqueue(new ICallBack<BaseEntity<List<CompanyAndDeptEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CompanyAndDeptEntity>> data) {
                DialogHelper.dismissProgressDialog();
                if (data != null && data.getData() != null){
                    departList.postValue(data.getData());
                }
            }
        });
    }
}
